package com.ld.control.business.sample.controller;


import com.ld.control.business.equipment.service.EquipmentService;
import com.ld.control.business.equipment.vo.resp.EquipmentDataFieldConfigRespVo;
import com.ld.control.business.equipment.vo.resp.EquipmentSampleFieldShowRespVo;
import com.ld.control.business.process.vo.resp.AllProcessExampleRespVo;
import com.ld.control.business.sample.service.SampleService;
import com.ld.control.business.sample.vo.resp.SampleDataFileRespVo;
import com.ld.control.business.sample.vo.resp.SampleExtRespVo;
import com.ld.control.business.sample.vo.resp.SampleRespVo;
import com.ld.control.common.ResultResponse;
import com.ld.control.common.vo.GenerateListVo;
import com.ld.control.common.vo.GeneratePageListVo;
import com.ld.control.sysenum.ResultResponseEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 样品表，存放任务的样品信息 前端控制器
 * </p>
 *
 * @author wangfeng
 * @since 2024-06-12
 */
@Tag(name = "样品相关接口")
@RestController
public class SampleController {

    @Autowired
    private SampleService sampleService;

    @Autowired
    private EquipmentService equipmentService;

    @GetMapping("/api/centralControl/sample/getEquipmentSampleFieldShowList")
    @Operation(summary = "根据设备id获取检测显示的字段")
    public ResultResponse<GenerateListVo<EquipmentDataFieldConfigRespVo>> getEquipmentSampleFieldShowList(
            @RequestParam Long equipmentId
    ) {
        List<EquipmentDataFieldConfigRespVo> equipmentSampleFieldShowRespVoList = equipmentService.getEquipmentSampleFieldShowList(equipmentId);
        return ResultResponse.success(new GenerateListVo<>(equipmentSampleFieldShowRespVoList));
    }

    @GetMapping("/api/centralControl/sample/getPageList")
    @Operation(summary = "根据条件搜索样品列表")
    public ResultResponse<GeneratePageListVo<List<String>>> getPageList(
            @RequestParam(required = false) Long taskExampleId,
            @RequestParam(required = false) Long equipmentId,
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size
    ) {
        GeneratePageListVo<List<String>> pageList = sampleService.getPageListExt1(taskExampleId, equipmentId, current, size);
        return ResultResponse.success(pageList);
    }

    @GetMapping("/api/centralControl/sample/downloadSampleData")
    @Operation(summary = "下载样品数据文件")
    public ResultResponse<ResultResponseEnum> downloadSampleData(
            HttpServletResponse response,
            @RequestParam(required = false) Long taskExampleId,
            @RequestParam(required = false) Long equipmentId
    ) {
        sampleService.downloadSampleData(response, taskExampleId, equipmentId);
        return ResultResponse.success();
    }

    @GetMapping("/api/centralControl/sample/getSampleDataFileList")
    @Operation(summary = "获取样品检测报告文件")
    public ResultResponse<GenerateListVo<SampleDataFileRespVo>> getSampleDataFileList(
            @RequestParam(required = false) Long taskExampleId
    ) {
        List<SampleDataFileRespVo> resultList = sampleService.getSampleDataFileList(taskExampleId);
        return ResultResponse.success(new GenerateListVo<>(resultList));
    }


    @GetMapping("/api/centralControl/sample/getPageListV2")
    @Operation(summary = "获取所有样品数据")
    public ResultResponse<GeneratePageListVo<SampleExtRespVo>> getEquipmentSampleFieldShowList(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size
    ) {
        GeneratePageListVo<SampleExtRespVo> pageList = sampleService.getPageList(current, size);
        return ResultResponse.success(pageList);
    }


}

